<template>
  <div class="step-three">
    <h3 class="requireh3">产品信息</h3>
    <!-- 产品信息 -->
    <m-form
      :hide-required-asterisk="true"
      class="form-product"
      label-width="92px"
      label-position="right"
    >
      <m-form-item label="产品名称：" class="product-item product-name no-icon">
        <div class="content">{{ mydata.goods_info }}</div>
      </m-form-item>
      <m-form-item label="产品类型：" class="product-item product-type no-icon">
        <div class="content">
          {{ mydata.goods_type == 1 ? "包装材料" : "配套服务" }}
        </div>
      </m-form-item>
      <m-form-item label="产品分类：" class="product-item product-sort no-icon">
        <div class="content" v-if="type != 'edit'">
          {{ mydata.goods_class_1_txt }} > {{ mydata.goods_class_2_txt }}
        </div>
        <div class="content" v-else>
          {{ mydata.class1 && mydata.class1.cate_name }} > {{ mydata.class2 && mydata.class2.cate_name }}
        </div>
      </m-form-item>
      <m-form-item
        label="产品数量："
        class="product-item product-quantity no-icon"
      >
        <div class="content">
          {{ mydata.goods_num }} {{ mydata.goods_unit_txt }}
        </div>
      </m-form-item>
      <m-form-item
        label="贸易条件："
        class="product-item product-trade-condition no-icon"
      >
        <div class="content">{{ mydata.goods_condition }}</div>
      </m-form-item>
      <m-form-item
        label="期望单价："
        class="product-item product-expected-price no-icon"
      >
        <div class="content">
          {{ mydata.goods_price }} {{ mydata.currency == 0 ? "人民币" : "元" }}
        </div>
      </m-form-item>
      <m-form-item
        label="产品图片："
        class="product-item product-pics product-annex no-icon"
      >
        <div class="pics-box" v-if="mydata.img_list">
          <div
            class="pic-item"
            v-for="(item, index) in mydata.img_list"
            :key="index"
          >
            <img :src="item" alt="" />
          </div>
        </div>
        <div class="content" v-else>
          <div class="annex-name">--</div>
        </div>
      </m-form-item>
      <m-form-item
        label="产品附件："
        class="product-item product-annex no-icon"
      >
        <div class="content">
          <div class="annex-name" v-if="mydata.file_list">
            {{ mydata.file_list[0] }}
          </div>
          <div class="annex-name" v-else>--</div>
        </div>
      </m-form-item>
    </m-form>
    <div class="line" />
    <!-- 配送与支付 -->
    <h3 class="requireh3">配送与支付</h3>
    <m-form
      :hide-required-asterisk="true"
      class="form-delivery"
      label-width="92px"
      label-position="right"
    >
      <m-form-item
        label="运输方式："
        class="delivery-item delivery-way no-icon"
      >
        <div class="content">{{ mydata.transport_type }}</div>
      </m-form-item>
      <m-form-item
        label="目的地："
        class="delivery-item delivery-destination no-icon"
      >
        <div class="content">{{ mydata.province }} {{ mydata.city }}</div>
      </m-form-item>
      <m-form-item
        label="详细地址："
        class="delivery-item delivery-address no-icon"
      >
        <div class="content">{{ mydata.address ||'--' }}</div>
      </m-form-item>
      <m-form-item
        label="期望交期："
        class="delivery-item delivery-date no-icon"
      >
        <div class="content">{{ mydata.days || '--' }}天</div>
      </m-form-item>
      <m-form-item
        label="支付方式："
        class="delivery-item delivery-payment no-icon"
      >
        <div class="content">
          {{ mydata.pay_type == 0 ? "线上支付" : "线下支付" }}
        </div>
      </m-form-item>
      <m-form-item
        label="备注："
        class="delivery-item delivery-remarks no-icon"
      >
        <div class="content">{{ mydata.remarks }}</div>
      </m-form-item>
      <div class="line" />
      <!-- 供应商 -->
      <h3 class="requireh3">选择供应商</h3>
      <div class="suppliers">
        <div class="suppliers-list">
          <div
            class="supplier-pic"
            v-for="(supplier, index) in suppliers"
            :key="index"
          >
            <div class="mask"></div>
            <div class="pic-box">
              <img :src="supplier.mer_avatar" alt="" class="object" />
            </div>
            <p class="supplier-name">{{ supplier.mer_name }}</p>
          </div>
        </div>
        <div class="suppliers-options">
          <checkbox-group v-model="mydata.supportList" disabled>
            <checkbox
              class="checkbox-item"
              name="all"
              shape="square"
              checked-color="#E48B2C"
            >
              使用全网发布权益
            </checkbox>
            <checkbox
              class="checkbox-item"
              name="zbz"
              shape="square"
              checked-color="#E48B2C"
            >
              仅发送该需求给站包装网认证供应商
            </checkbox>
            <checkbox
              class="checkbox-item"
              name="web"
              shape="square"
              checked-color="#E48B2C"
            >
              <div>我同意发送我的联系方式给到响应需求的供应商</div>
              <div class="hoverBox">
                <img
                  src="~/assets/images/icon-remarks.png"
                  alt=""
                  class="icon"
                />
                <div class="showTxt">
                  勾选此项,则平台会发送您的通讯方式给到响应需求的供应商,否则系统只提供您的姓名、公司、邮箱信息。
                </div>
              </div>
            </checkbox>
          </checkbox-group>
        </div>
      </div>
      <div class="line" />
      <!-- 发布规则 -->
      <h3 class="requireh3">发布规则</h3>
      <div class="rules">
        <div class="rules-options">
          <checkbox-group v-model="mydata.rulesCheckList">
            <checkbox
              class="checkbox-item"
              name="rule_72"
              shape="square"
              checked-color="#E48B2C"
            >
              如果72小时没有供应商响应，我同意将需求自动转入“委托平台”，由找包装网托管。
            </checkbox>
            <checkbox
              class="checkbox-item"
              name="agree"
              shape="square"
              checked-color="#E48B2C"
            >
              我已阅读 , 理解并同意找包装网的
              <a href="javascript:;" @click.stop="() => centerDialogVisible = true">发布需求</a> 规则 。
            </checkbox>
          </checkbox-group>
        </div>
      </div>
    </m-form>
    <!-- 发布需求规则 -->
    <Dialog
      :title="platformRules.title"
      :visible.sync="centerDialogVisible"
      width="30%"
      class="plat-rules"
      center>
      <span v-html="platformRules.content"></span>
    </Dialog>
  </div>
</template>

<script>
import { Checkbox, CheckboxGroup } from "vant"
import MForm from "@/components/common/m-form/MForm"
import MFormItem from "@/components/common/m-form/MFormItem"
import { platformRules } from '@/request/api'
import { Dialog } from 'element-ui'

export default {
  name: "Requirement3",
  props: {
    type: String,
    mydata: {
      type: Object
    }
  },
  components: { MFormItem, MForm, Checkbox, CheckboxGroup, Dialog },
  data() {
    return {
      suppliers: [],
      platformRules: {},
      centerDialogVisible: false
    }
  },
  created() {
    if (!this.mydata.address) {
      this.$parent.active = 0
      this.$router.push({ path: "/require/1" }) // TODO 跳转路径报错
    }
    this.suppliers = JSON.parse(localStorage.getItem("shopPic"))
    this.getRules()
  },
  methods: {
    getRules() {
      if(!this.platformRules) {
        platformRules(2).then(res => {
          this.platformRules = res.data
        }).catch(err => {
          this.$message.error(err.message)
        })
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "~@/assets/style/common.scss";
/deep/ .van-checkbox {
  overflow: unset;
}
.plat-rules /deep/ .el-dialog__body {
  height: 350px;
  overflow-y: auto;
}
.hoverBox {
  width: 15px;
  height: 15px;
  position: relative;
}
.hoverBox .showTxt {
  display: none;
  border: 1px solid #eee;
  background: #fff;
  padding: 20px;
  width: 400px;
  position: absolute;
  left: 30px;
  top: -32px;
  height: 82px !important;
  font-size: 12px;
  line-height: 20px;
}
.hoverBox .showTxt::before {
  content: "";
  border: 6px solid transparent;
  border-right-color: #eee;
  position: absolute;
  left: -12px;
  top: 50%;
  margin-top: -6px;
}
.hoverBox:hover .showTxt {
  display: block;
}
.step-three {
  .requireh3 {
    margin-bottom: 14px;
  }

  .line {
    height: 1px;
    background: #e9e9e9;
    margin: 58px 0;
  }

  .product-item,
  .delivery-item {
    .content {
      height: 100%;
      display: flex;
      align-items: flex-end;
      font-size: 16px;
    }

    /deep/ .m-form-item__label {
      min-width: 93px;
      padding-left: 0;
      display: flex;
      align-items: flex-start;
    }
  }

  .form-product {
    .product-pics {
      .pics-box {
        .pic-item {
          display: inline-block;
          position: relative;

          &:not(:last-of-type) {
            margin-right: 10px;
          }

          img {
            width: 240px;
            // height: 140px;
            object-fit: cover;
          }
        }
        .pic-item:first-of-type:after {
          content: "封面";
          color: #fff;
          background: #0085e8;
          font-size: 12px;
          height: 20px;
          line-height: 20px;
          border-radius: 12px;
          position: absolute;
          right: 10px;
          top: 10px;
          z-index: 10;
          width: 50px;
          text-align: center;
        }
      }
    }

    .product-annex {
      .content {
        display: flex;
        align-items: center;

        img {
          width: 38px;
          height: 38px;
        }

        .annex-name {
          margin-left: 10px;
          display: inline-block;
          font-size: 13px;
          color: #bbbbbb;
        }
      }
    }
  }


  .suppliers {
    .suppliers-list {
      margin-top: 38px;
      display: flex;
      flex-wrap: wrap;
      margin-right: -12px;

      .supplier-pic {
        width: 166px;
        margin-right: 6px;
        margin-bottom: 20px;
        position: relative;

        .pic-box {
          height: 130px;
        }

        .supplier-name {
          margin-top: 10px;
          text-align: center;
          z-index: 100;
        }

        .mask {
          display: none;
          position: absolute;
          top: 0;
          left: 0;
          width: 166px;
          height: 100%;
          background: rgba(0, 0, 0, 0.4);
          z-index: 99;
        }

        &:hover {
          .supplier-name {
            color: #fff;
            margin-top: -8px;
            transition: all 0.3s;
            position: relative;
          }

          .mask {
            display: block;
          }
        }
      }
    }

    .suppliers-options {
      margin-top: 38px;

      .checkbox-item {
        margin-bottom: 20px;
        font-size: 14px;

        &:nth-of-type(3) {
          /deep/ .van-checkbox__label {
            display: flex;
            align-items: center;

            div {
              height: 17px;
            }

            img {
              width: 15px;
              height: 15px;
              margin: 0 5px;
            }
          }
        }
      }
    }
  }

  .rules {
    margin-top: 38px;

    .rules-options {
      .checkbox-item {
        margin-bottom: 20px;
        font-size: 14px;

        &:nth-of-type(2) {
          a {
            color: $theme-color-1;
            font-weight: bold;
          }
        }
      }
    }
  }
}
</style>
